<template>
	<div>
		<el-dialog title="添加" width="70%" class="icon-dialog" :visible.sync="show" @open="open" :before-close="closeForm" append-to-body>
			<el-form :size="size" ref="form" :model="form" :rules="rules" :label-width="$store.getters.device !== 'mobile'?'16%':'90px'">
 				 <el-row >
					<el-col :span="24">
						<el-form-item label="公告标题" prop="notice_title">
							<el-input  v-model="form.notice_title" autoComplete="off" clearable  placeholder="请输入公告标题"></el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row>
				   <el-col :span="24">
                        <el-form-item label="公告类型" prop="notice_type">
                            <el-select style="width:100%" v-model="form.notice_type" :size="size" clearable filterable placeholder="请选择">
                                <el-option key="0"  label="通知" :value="1"></el-option>
                                <el-option key="1"  label="公告" :value="2"></el-option>
                            </el-select>
                        </el-form-item>
                   </el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item label="公告内容" prop="notice_content">
							<TinymceEditor v-if="show" tinymceId="notice_content"  :tinymceContent.sync="form.notice_content"></TinymceEditor>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item label="公告状态" prop="status">
							<el-switch :active-value="1" :inactive-value="0" v-model="form.status"></el-switch>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item label="备注" prop="remark">
							<el-input  v-model="form.remark" autoComplete="off" clearable  placeholder="请输入备注"></el-input>
						</el-form-item>
					</el-col>
				 </el-row>
				</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button :size="size" :loading="loading" type="primary" @click="submit" >
					<span v-if="!loading">确 定</span>
					<span v-else>提 交 中...</span>
				</el-button>
				<el-button :size="size" @click="closeForm">取 消</el-button>
			</div>
		</el-dialog>
	</div>
</template>
<script>
import { add } from '@/api/admin/notice'
import TinymceEditor from '@/components/editor/TinymceEditor.vue'


export default {
	name:'noticeadd',
	components: {
	   		TinymceEditor,
	},
	props: {
		show: {
			type: Boolean,
			default: false
		},
		size: {
			type: String,
			default: 'small'
		},
	},
	data(){
		return {
			form: {
			   notice_title:'',
			   notice_type:1,
			   notice_content:'',
			   status:1,
			   remark:'',
			},
			loading:false,
			rules: {
			}
		}
	},
	watch:{
		show(val){
			if(val){
			}
		}
	},
	methods: {
		open(){
		},
		submit(){
			this.$refs['form'].validate(valid => {
				if(valid) {
					this.loading = true
					add(this.form).then(res => {
						if(res.status == 200){
							this.$message({message: '操作成功', type: 'success'})
							this.$emit('refresh_list')
							this.closeForm()
						}
					}).catch(()=>{
						this.loading = false
					})
				}
			})
		},
		closeForm(){
			this.$emit('update:show', false)
			this.loading = false
			if (this.$refs['form']!==undefined) {
				this.$refs['form'].resetFields()
			}
		},
	}
}
</script>
<style scoped lang="scss">
@import '@/assets/scss/common.scss'
</style>
